/** 
 * @Ajax CRUD
 * @author xxz 
 * @version 1.0.0  
 * @依赖 jquery.js
 */
if(typeof(QualityCheck) === "undefined"){
	QualityCheck = {AjaxCRUD:{}};
}else{
	if(typeof(QualityCheck.AjaxCRUD) === "undefined") QualityCheck.AjaxCRUD = {};
}
QualityCheck.AjaxCRUD.get =  function (url,obj,onsucc,onfail,onerror){
	var random = "?random="+Math.random();
	$.ajax({
		url: url + random, type: "get", async: true, dataType: "json",
		contentType:"application/json; charset=utf-8",
		data:{param:JSON.stringify(obj)},
		success: function(data, status, detail){
			if(status=="success"){
				if(typeof onsucc === "function") onsucc(data);
			}
			else{
				if(typeof onfail === "function") onfail();
			}
	    },error:function(){
	    	if(typeof onerror === "function"){
	    		onerror();
	    	}else{
	    		//if(typeof onfail === "function") onfail();
	    	}
	    }	
    });
};
QualityCheck.AjaxCRUD.get2 =  function (url,obj,onsucc,onfail,onerror){
	var random = "?random="+Math.random();
	$.ajax({
		url: url + random, type: "get", async: true, dataType: "json",
		contentType:"application/json; charset=utf-8",
		data:{param:JSON.stringify(obj)},
		success: function(data, status, detail){
			if(status=="success"){
				if(typeof onsucc === "function") onsucc(data);
			}
			else{
				if(typeof onfail === "function") onfail();
			}
	    },error:function(){
	    	if(typeof onerror === "function"){
	    		onerror();
	    	}else{
	    		//if(typeof onfail === "function") onfail();
	    	}
	    }	
    });
};
QualityCheck.AjaxCRUD.add = function(url,obj,onsucc,onfail,onerror){
	var random = "?random="+Math.random();
	$.ajax({
		url: url + random , type: "post", async: true, dataType: "json",
		data:{param: JSON.stringify(obj)},
		success: function(data, status, detail){
			if(status=="success"){
				if(typeof onsucc === "function") onsucc(data);
			}
			else{
				if(typeof onfail === "function") onfail();
			}
	    },error:function(){
	    	if(typeof onerror === "function"){
	    		onerror();
	    	}else{
	    		if(typeof onfail === "function") onfail();
	    	}
	    }
    });
};
QualityCheck.AjaxCRUD.update = function(url,obj,onsucc,onfail,onerror){
	var random = "?random="+Math.random();
	$.ajax({
		url: url + random , type: "put", async: true, dataType: "json",
		processData: false, data:{param:JSON.stringify(obj)},
		success: function(data, status, detail){
			if(status=="success"){
				if(typeof onsucc === "function") onsucc(data);
			}
			else{
				if(typeof onfail === "function") onfail();
			}
	    },error:function(){
	    	if(typeof onerror === "function"){
	    		onerror();
	    	}else{
	    		if(typeof onfail === "function") onfail();
	    	}
	    }
    });
};
QualityCheck.AjaxCRUD.remove =  function (url,obj,onsucc,onfail,onerror){
	var random = "?random="+Math.random();
	$.ajax({
		url: url  + random , type: "delete", async: true, dataType: "json",
		data:{param:JSON.stringify(obj)},
		success: function(xml, status, detail){
			if(status=="success"){
				if(typeof onsucc === "function") onsucc($(xml));
			}
			else{
				if(typeof onfail === "function") onfail();
			}
	    },error:function(){
	    	if(typeof onerror === "function"){
	    		onerror();
	    	}else{
	    		if(typeof onfail === "function") onfail();
	    	}
	    }	
    });
};
